package ac2.util.serial.handlers;

import ac2.Global;
import ac2.util.TemperatureReadingConverter;
import ac2.util.TemperatureReadingConverter.TemperatureFormat;
import ac2.util.sensors.sht11.SHT11TemperatureReadingConverter;
import ac2.util.serial.packets.IBytePacket;
import ac2.util.serial.packets.TemperatureUpdatePacket;

public class TemperatureUpdatePacketHandler extends AC2PacketHandler {

	public void handlePacket(IBytePacket genericPacket) {
		
		TemperatureUpdatePacket packet = (TemperatureUpdatePacket) genericPacket;
		
		Global.Debug("TemperatureUpdatePacketHandler");
		Global.Debug("   Object = " + packet.toString());
        Global.Debug("   Reading = " + packet.getReading());
		Global.Debug("   Count = " + packet.getCount());
		
		TemperatureReadingConverter converter = new SHT11TemperatureReadingConverter();
		
		double temp = converter.ConvertReading(packet.getReading(), TemperatureFormat.Fahrenheit);
		
		String url = BaseUrl + "/reading/add/zone/" + packet.getSenderNode() + 
			"/reading/" + temp +
			"/count/" + packet.getCount();

		sendCommand(url);
	}

}
